寫好 tick 交易策略之後,需要回測一下當天的買賣進出點是否正確
ticks = api.ticks(
contract=api.Contracts.Stocks["2330"],
date="2021-09-22"
)
ticks
格式內容為
Ticks(
ts=[1583312400821000000, 1583312405836000000, 1583312410849000000, 1583312415864000000, 1583312420877000000],
close=[322.0, 321.5, 321.0, 321.0, 321.0],
volume=[5098, 91, 126, 59, 90],
bid_price=[321.5, 321.0, 321.0, 321.0, 321.0],
bid_volume=[5, 100, 94, 78, 20],
ask_price=[322.0, 321.5, 321.5, 321.5, 321.5],
ask_volume=[646, 13, 31, 86, 199]
)
可以簡單的轉換成
ts=[1583312400821000000, 1583312405836000000, 1583312410849000000, 1583312415864000000, 1583312420877000000]
close=[322.0, 321.5, 321.0, 321.0, 321.0]
volume=[5098, 91, 126, 59, 90]
bid_price=[321.5, 321.0, 321.0, 321.0, 321.0]
bid_volume=[5, 100, 94, 78, 20]
ask_price=[322.0, 321.5, 321.5, 321.5, 321.5]
ask_volume=[646, 13, 31, 86, 199]
for i in range(len(close)):
if bid_price[i] == close[i]:
ticktype = 2
elif ask_price[i] == close[i]:
ticktype = 1
VolSum = VolSum + volume[i]
quote = {
'AmountSum': [866407850.0],
'Close': [close[i]],
'Date': '2021/08/24',
'TickType': [ticktype],
'Time': datetime.utcfromtimestamp((int(ts[i])/1000000000)).strftime('%H:%M:%S'),
'VolSum': [VolSum],
'Volume': [volume[i]]
}
quote_callback(topic, quote)
如此這樣就可以在沒有開盤的時候執行策略測試了